package com.zyw.controller.order;


import com.zyw.entity.Clothing;
import com.zyw.entity.ClothingCategory;
import com.zyw.entity.OrderClient;
import com.zyw.from.ClothingFrom;
import com.zyw.from.OrderFrom;
import com.zyw.service.order.OrderClientService;
import com.zyw.util.ResultVOUtil;
import com.zyw.vo.LayUITableVO;
import com.zyw.vo.ResultVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@Slf4j
@RequestMapping("/order/client")
public class OrderClientController {


    @Autowired
    public OrderClientService orderClientService;

    //菜品类别展示
    @GetMapping("/index")
    public String index(Model model){


        return "order/client/index";

    }

    //获取菜品类别信息
    @GetMapping("/list")
    @ResponseBody
    public LayUITableVO<List<OrderClient>> list (@RequestParam(defaultValue = "1") Integer page,
                                                 @RequestParam(defaultValue = "10") Integer limit,
                                                 OrderFrom from){

        Map<String ,Object> map = new HashMap<>();
        map.put("page",page);
        map.put("limit",limit);
        map.put("from",from);
        LayUITableVO< List<OrderClient>> vo = orderClientService.findPage(map);


        return vo;
    }

    //修改菜品类别信息1（查询指定id菜品分类详情）
    @GetMapping("/edit-ui")
    public String editUI(String id,Model model){

        OrderClient orderClient = orderClientService.selectById(id);


        model.addAttribute("orderClient",orderClient);

        return "order/client/edit";

    }

    //执行修改
    @PostMapping("/edit")
    @ResponseBody
    public ResultVO edit(OrderClient orderClient){

        orderClientService.update(orderClient);

        return ResultVOUtil.ok();
    }

    //修改菜品类别信息1（查询指定id菜品分类详情）
    @GetMapping("/add-ui")
    public String addUI(Model model){


        return "order/client/add";

    }

    //执行修改
    @PostMapping("/add")
    @ResponseBody
    public ResultVO add(OrderClient orderClient){

        orderClientService.save(orderClient);

        return ResultVOUtil.ok();
    }


    //执行删除
    @PostMapping("/del")
    @ResponseBody
    public ResultVO del(String id){
        orderClientService.delelteById(id);
        return ResultVOUtil.ok();
    }


}
